updating oE int_to_bits
int_to_bits
include convert.e namespace convert public function int_to_bits(atom x, integer nbits = 32)
extracts the lower bits from an integer.
Parameters:
- x : the atom to convert
- nbits : the number of bits requested. The default is 32.
Returns:
A sequence, of length nbits, made of 1's and 0's.
Comments:
x should have no fractional part. If it does, then the first "bit" will be an atom between 0 and 2.
The bits are returned lowest first.
For negative numbers the two's complement bit pattern is returned.
You can use operators like subscripting/slicing/and/or/xor/not on entire sequences to manipulate sequences of bits. Shifting of bits and rotating of bits are easy to perform.
Example 1:
s = int_to_bits(177, 8) -- s is {1,0,0,0,1,1,0,1} -- "reverse" order
See Also:
bits_to_int, int_to_bytes, Relational operators, operations on sequences
Not Categorized, Please Help
|